package Ep06_BinaryTree.BFS.T9_0104;

import Ep06_BinaryTree.TreeNode;

import java.util.Deque;
import java.util.LinkedList;

public class Mine {
    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        Deque<TreeNode> deque = new LinkedList<>();
        deque.offer(root);
        int depth = 0;
        while (!deque.isEmpty()) {
            int size = deque.size();
            while (size > 0){
                TreeNode tempNode = deque.poll();
                if (tempNode.left != null) deque.offer(tempNode.left);
                if (tempNode.right != null) deque.offer(tempNode.right);
                size--;
            }
            depth++;
        }
        return depth;
    }
}
